package com.ai.module.mj.domain;

import com.ai.module.chat.util.DateUtils;
import com.ai.module.mj.constant.enums.TaskAction;
import com.ai.module.mj.constant.enums.TaskStatus;
import com.ai.module.mj.domain.bo.MJDataUrl;
import com.ai.module.mj.domain.enu.ImageTaskSource;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.ArrayList;
import java.util.List;

import static com.ai.module.chat.common.constant.StringConstant.FAST;


@Data
@EqualsAndHashCode(callSuper = true)
@ApiModel("任务")
public class Task extends DomainObject {

    private static final long serialVersionUID = -674915748204390789L;

    @ApiModelProperty("任务类型")
    private TaskAction action;

    @ApiModelProperty("任务状态")
    private TaskStatus status = TaskStatus.NOT_START;

    @ApiModelProperty("提示词")
    private String prompt;

    @ApiModelProperty("最终提示词")
    private String finalPrompt;

    @ApiModelProperty("提示词-英文")
    private String promptEn;

    @ApiModelProperty("任务描述")
    private String description;

    @ApiModelProperty("自定义参数")
    private String state;

    @ApiModelProperty("提交时间")
    private String submitTime;

    @ApiModelProperty("开始执行时间")
    private String startTime;
    @ApiModelProperty("开始执行时间")
    private Long startTimeL;

    private Long start;

    @ApiModelProperty("结束时间")
    private String finishTime;

    private String userId;

    private int userIntId;

    @ApiModelProperty("缩略图片url")
    private String imageUrl;

    @ApiModelProperty("图片url")
    private String scaleUrl;

    @ApiModelProperty("任务进度")
    private String progress;

    @ApiModelProperty("失败原因")
    private String failReason;

    private String robotId;

    private List<MJDataUrl> dataUrls = new ArrayList<>();

    private String drawType = "FAST";

    private Integer realPoint = 0;

    private String uuid;

    private String imageGroundPrompt;

    private String speedType = FAST;

    private String loginToken;
    //      自定义参数
    private String otherPrompt;

    private String crefPrompt;

    private List<String> imageDescList;

    private List<String> fileUrlList= new ArrayList<>();

    private ImageTaskSource taskSource = ImageTaskSource.commonImage;

    public void start() {
        this.startTime = DateUtils.getCurrentTime();
        this.startTimeL =System.currentTimeMillis();
        this.status = TaskStatus.SUBMITTED;
        this.progress = "0%";
        this.start = System.currentTimeMillis();
    }

    public void success() {
        this.finishTime = DateUtils.getCurrentTime();
        this.status = TaskStatus.SUCCESS;
        this.progress = "100%";
    }

    public void fail(String reason) {
        this.finishTime = DateUtils.getCurrentTime();
        this.status = TaskStatus.FAILURE;
        this.failReason = reason;
        this.progress = "";
    }

    public void setPromptEn(String promptEn) {
        if (this.promptEn  == null){
            this.promptEn  = promptEn + getOtherPrompt();
            return;
        }
        this.promptEn  = this.promptEn + promptEn ;
    }

    public void setRealPromptEn(String promptEn) {
        // 进行 值处理
        this.promptEn  = promptEn;
    }

    public String getOtherPrompt() {
        if (otherPrompt ==null){
            return "";
        }
        return otherPrompt;
    }
}
